package com.zlict.admin.controller;

import com.zlict.admin.domain.ProjectMember;
import com.zlict.admin.service.IProjectMemberService;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.core.page.TableDataInfo;
import com.zlict.common.enums.BusinessType;
import com.zlict.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目人员Controller
 * 
 * @author dzw
 */
@RestController
@RequestMapping("/admin/member")
public class ProjectMemberController extends BaseController
{
    @Autowired
    private IProjectMemberService projectMemberService;

    /**
     * 查询项目人员列表
     */
    @PreAuthorize("@ss.hasPermi('admin:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectMember projectMember)
    {

        //todo 需要连人员表

        startPage();
        List<ProjectMember> list = projectMemberService.selectProjectMemberList(projectMember);
        return getDataTable(list);
    }

    /**
     * 导出项目人员列表
     */
    @PreAuthorize("@ss.hasPermi('admin:member:export')")
    @Log(title = "项目人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectMember projectMember)
    {
        List<ProjectMember> list = projectMemberService.selectProjectMemberList(projectMember);
        ExcelUtil<ProjectMember> util = new ExcelUtil<>(ProjectMember.class);
        util.exportExcel(response, list, "项目人员数据");
    }

    /**
     * 获取项目人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectMemberService.selectProjectMemberById(id));
    }

    /**
     * 新增项目人员
     */
    @PreAuthorize("@ss.hasPermi('admin:member:add')")
    @Log(title = "项目人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProjectMember projectMember)
    {
        return toAjax(projectMemberService.insertProjectMember(projectMember));
    }
    /**
     * 批量新增项目人员
     */
    @PreAuthorize("@ss.hasPermi('admin:member:add')")
    @Log(title = "项目人员", businessType = BusinessType.INSERT)
    @PostMapping("/addProjectMembers")
    public AjaxResult addProjectMembers(@RequestBody ProjectMember projectMember)
    {
        return toAjax(projectMemberService.insertProjectMembers(projectMember));
    }




    /**
     * 修改项目人员
     */
    @PreAuthorize("@ss.hasPermi('admin:member:edit')")
    @Log(title = "项目人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectMember projectMember)
    {
        return toAjax(projectMemberService.updateProjectMember(projectMember));
    }

    /**
     * 删除项目人员
     */
    @PreAuthorize("@ss.hasPermi('admin:member:remove')")
    @Log(title = "项目人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectMemberService.deleteProjectMemberByIds(ids));
    }
}